Skip to content

feat: replace assets state references confirmations#29726

Merged
bergarces merged 6 commits into
mainfrom
replace-assets-state-references-confirmations
May 7, 2026
Merged

feat: replace assets state references confirmations#29726
bergarces merged 6 commits into
mainfrom
replace-assets-state-references-confirmations

Conversation

@bergarces
Copy link
Copy Markdown
Contributor

@bergarces bergarces commented May 5, 2026

Description

The new AssetsController is being introduced to replace most controllers from @metamask/assets-controllers. This is one of many PRs that replace direct access to legacy state with selectors that, using a feature flag, handle the transition between the legacy state and the new state when the flag is turned on.

Changelog

CHANGELOG entry: null

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/ASSETS-2827

Manual testing steps

Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]

Screenshots/Recordings

Before

After

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Medium Risk
Updates how native balances are looked up for gas_insufficient_native_asset, which could change metrics output if address casing/normalization differs across callers. Scoped to analytics/metrics code with test adjustments, but affects transaction-finalized event properties.

Overview
Updates gas metrics to read account balances via the selectAccountsByChainId selector instead of directly accessing AccountTrackerController state, aligning with the ongoing assets-state migration.

getNativeBalance now resolves the sender address with safeToChecksumAddress and looks up balances by checksummed key (removing the previous .toLowerCase() access). Tests were updated to use a realistic checksummed address and store balances under that exact key.

Reviewed by Cursor Bugbot for commit f71e6c6. Bugbot is set up for automated code reviews on this repo. Configure here.

@bergarces bergarces requested a review from a team as a code owner May 5, 2026 12:28
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

state.engine?.backgroundState?.AccountTrackerController?.accountsByChainId;
const accountsByChainId = selectAccountsByChainId(state);

const account = accountsByChainId?.[chainId]?.[address?.toLowerCase()];
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was broken. In the current state, the addresses in accountsByChainId are stored in checksum format.

Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 325394d. Configure here.

Comment thread app/core/Engine/controllers/transaction-controller/metrics_properties/gas.ts Outdated
@github-actions github-actions Bot added size-S and removed size-XS labels May 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

🔍 Smart E2E Test Selection

  • Selected E2E tags: None (no tests recommended)
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: low
  • AI Confidence: 95%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes are confined to two files in the transaction-controller metrics_properties directory:

  1. gas.ts: Refactors getNativeBalance() to use the selectAccountsByChainId selector instead of directly accessing Redux state, and switches from lowercase address lookup to checksummed address lookup via safeToChecksumAddress. This is a bug fix/refactor in the analytics/metrics path only.

  2. gas.test.ts: Updates unit tests to use a proper checksummed Ethereum address instead of the mock '0xuser' string, aligning with the new implementation.

Why no E2E tags are needed:

  • These changes only affect transaction gas metrics/analytics telemetry (what gets reported when a transaction is finalized), not the actual transaction execution, confirmation UI, gas estimation, or any user-facing flow.
  • The fix is internal to the metrics pipeline — it corrects how the native balance is looked up for analytics purposes.
  • No UI components, navigation, modals, or user flows are modified.
  • The changes are well-covered by unit tests.
  • No shared infrastructure (Engine initialization, controllers, navigation) is affected.

Why no performance tests are needed:

  • The change is a minor refactor of an analytics helper function — replacing direct state access with a selector and fixing address casing. No rendering, data loading, or critical user flow performance is impacted.

Performance Test Selection:
The changes are limited to a metrics/analytics helper function for gas properties. No UI rendering, data loading, account list, or critical user flow performance is affected.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 5, 2026

@bergarces bergarces added this pull request to the merge queue May 7, 2026
Merged via the queue into main with commit 99ff9c5 May 7, 2026
64 checks passed
@bergarces bergarces deleted the replace-assets-state-references-confirmations branch May 7, 2026 14:27
@github-actions github-actions Bot locked and limited conversation to collaborators May 7, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.77.0 Issue or pull request that will be included in release 7.77.0 label May 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.77.0 Issue or pull request that will be included in release 7.77.0 size-S team-assets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants